var table = $('#enterpriseList').DataTable({
//    "processing": true,
//    "serverSide": true,
    "ajax": "enterprise/getData",
    "columns": [
        {"data": "user"},
        {"data": "name"},
        {"data": "shortName"},
        {"data": "orgCode"},
        {"data": "bizLicense"},
        {"data": "taxRegNo"},
        {"data": "bankLicense"},
        {"data": "user"},
        {"data": "registerTime"},
        {"data": "id"}
    ],
    "aoColumnDefs": [{
            "targets": 0,
            "mRender": function (data, type, row) {
                return '<a href="enterprise/index/' + data.id + '" target="_blank">' + data.loginName + '</a>';
            }
        }, {
            "targets": -3,
            "searchable": false,
            "mRender": function (data, type, row) {
                var status = data.enabled
                    ? '<i class="fa fa-check text-success"></i>正常'
                    : '<i class="fa fa-lock text-danger mr4"></i>冻结';
                return status;
            }
        }, {
            "targets": -2,
            "searchable": false,
            "visible": false,
            "mRender": function (data, type, row) {
                return $.format.date(new Date(data), "yyyy/MM/dd");
            }
        }, {
            "targets": -1,
            "bSortable": false,
            "searchable": false,
            "mRender": function (data, type, row) {
                var operations = $("#operationHTML").html().replace(/#id/g, row.userId).replace(/#loginName/g, row.user.loginName).replace(/#enabled/g, row.user.enabled);
                if (!row.user.enabled) {
                    operations = operations.replace("glyphicons-lock", "glyphicons-unlock").replace("冻结", "激活");
                }
                return operations;
            }
        }],
    "order": [[8, "desc"]],
    "oLanguage": chinese,
    "iDisplayLength": 5,
    "aLengthMenu": [
        [5, 10, 25, 50, -1],
        [5, 10, 25, 50, "全部"]
    ],
    "sDom": '<"dt-panelmenu clearfix"l<"pull-right"Tf>r>t<"dt-panelfooter clearfix"ip>',
    "oTableTools": {
        "aButtons": [{
                "sExtends": "copy",
                "sButtonText": "复制",
                "fnComplete": function (nButton, oConfig, oFlash, sFlash) {
                    alert('列表内容已复制到剪贴板');
                }
            }, {
                "sExtends": "xls",
                "sButtonText": "导出为Excel"
            }
        ],
        "sSwfPath": root_path + "/js/plugins/datatables/extensions/TableTools/swf/copy_csv_xls_pdf.swf"
    }
});
/**
 * 更改企业账号状态
 * @param {type} userId
 * @returns {undefined}
 */
function changeStatus(userId, enabled) {
    var msg = enabled === 'true' ? '确定冻结企业账号？' : '确定激活企业账号？';
    if (confirm(msg)) {
        $.get("user/changeStatus/" + userId, function (res) {
            if (res.success) {
                alert(res.message);
                location.reload();
            } else {
                alert("企业状态更新失败");
            }
        }).fail(function() {
            alert("服务器错误");
        });
    }
}